package java_class_work.socketDemo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @Author Tiam
 * @Date 2022/11/9 17:11
 * @Description:
 */
public class ClientThread implements Runnable {
    Socket socket;

    public ClientThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        readMessage();
    }

    private void readMessage() {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        } catch (IOException e) {
            e.printStackTrace();
        }

        while (true){
            try {
                System.out.println("等待读取消息...");
                String s = br.readLine();
                System.out.println(s);
            } catch (IOException e) {
                System.out.println("服务器断开");
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }
}
